home *** CD-ROM | disk | FTP | other *** search
- Path: dispatch.news.demon.net!demon!fe-line.demon.co.uk
- From: faye@fe-line.demon.co.uk (Faye Pearson)
- Newsgroups: comp.lang.c
- Subject: Is it me? or does time() not work as specified?
- Date: Thu, 15 Feb 1996 22:44:03 GMT
- Organization: fe-line
- Message-ID: <3123a1ca.41523@news>
- NNTP-Posting-Host: fe-line.demon.co.uk
- X-NNTP-Posting-Host: fe-line.demon.co.uk
- X-Newsreader: Forte Agent .99c/16.141
-
- Hi All, hope you can help?
-
- Compiler: Turbo C++ 3.0
-
- problem: time() documented to give seconds GMT since 1970. gives GMT+5
- localtime() gives correct GMT when daylight=0 and timezone=0
-
- example:
- #include <stdio.h>
- #include <time.h>
- #include <dos.h>
-
- void main()
- {
- long now;
- struct tm *tm_st;
-
-
- daylight=0; // This should make localtime() return GMT.
- timezone=0; // <------
-
- time(&now); // This should return the GMT seconds since etc.
-
- tm_st=localtime(&now); // GMT+0
-
- printf("\nWith localtime()\n");
- printf("%d:%d:%d ",tm_st->tm_hour,tm_st->tm_min,tm_st->tm_sec);
- printf("%d/%d/%d",tm_st->tm_mday,tm_st->tm_mon+1,tm_st->tm_year);
-
- tm_st=gmtime(&now); // Shouldn't this also be GMT+0??
-
- printf("\nWith gmtime()\n");
- printf("%d:%d:%d ",tm_st->tm_hour,tm_st->tm_min,tm_st->tm_sec);
- printf("%d/%d/%d",tm_st->tm_mday,tm_st->tm_mon+1,tm_st->tm_year);
- }
-
- Results:
-
- With localtime()
- 21:4:41 15/2/96 <--- This is the correct GMT
- With gmtime()
- 2:4:41 16/2/96 <--- GMT+5!!!!
-
- Can anyone explain this? and whether it is consistent between
- compilers?
-
- Faye
-